package com.rent.message.service.impl;


import com.rent.message.constant.MessageConstant;
import com.rent.message.pojo.dto.SendMessageDto;
import com.rent.message.pojo.dto.SystemMessageDto;
import com.rent.message.service.SystemMessageService;
import com.rent.message.ws.MessagePushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Service
public class SystemMessageServiceImpl implements SystemMessageService {


    @Autowired
    private MessagePushService messagePushService;

    @Override
    public void sendSystemMessage(SystemMessageDto dto) {
        if (Objects.equals(dto.getGetUserId(), SystemMessageDto.ALL_SYSTEM_USER_ID)){
            //TODO:发送给所有用户
            messagePushService.broadMessageAllUsers(dto);
        }else{
            //TODO:发送给指定用户
            Map<String, Object> message = new HashMap<>();
            message.put("type", MessageConstant.MESSAGE_TYPE_SYSTEM);
            message.put("from", 0L);
            message.put("content", dto.getContent());
            message.put("timestamp", System.currentTimeMillis());
            messagePushService.sendNoticeToUser(dto.getGetUserId().toString(),message);
        }
    }
}
